package com.ken.astroboy.quartz;

import java.io.IOException;

import com.ken.astroboy.core.InMemoryStorage;
import com.ken.astroboy.logic.LogicProcess;
import com.ken.astroboy.model.ScheduledTaskCustomData;
import com.ken.astroboy.service.WxService;
import com.ken.astroboy.util.Exceptions;

public class SendSignInRecordJob extends AbstractJob{

	@Override
	void doJob(ScheduledTaskCustomData customData) throws IOException {
		
		int i = 0;
		int limit = 32;
		int pauseTime = 30000;
		
		for(String group : customData.getGroupReceivers()){		
			
			if(InMemoryStorage.userGroupCtrlEntity.getSignInGroupList().contains(group)){
				
				if(i >= limit){
					logger.info("已发送群数等于{}，休眠{}ms再继续发送", i, pauseTime);
					i = 0;
					try {
						Thread.sleep(pauseTime);
					} catch (InterruptedException e) {
						logger.info(Exceptions.getExceptionDetail(e));
					}
				}else{
					i++;
				}
				
				WxService.sendTextMsg( LogicProcess.getSignInRecord(group), InMemoryStorage.groupMap.get(group).getUserName() );						
			}					
		}		
	}
}